module EasyForm
  module Wrappers
    class Leaf
      attr_reader :namespace

      def initialize(namespace, options = {})
        @namespace, @options = namespace, options
      end

      def render(input)
        #反射调用方法
        method = input.method(@namespace)

        #判断方法参数个数
        if method.arity.zero?
          ActiveSupport::Deprecation.warn <<-WARN
#{name} method now accepts a `wrapper_options` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:

    def #{name}

to

    def #{name}(wrapper_options)
          WARN

          method.call
        else
          method.call @options
        end
      end

      def find(name)
        self if @namespace == name
      end
    end
  end
end